const Router = require('@koa/router');
const schemaController = require('../../controllers/schemaController');
const { authenticate } = require('../../middleware/authMiddleware');

const router = new Router({
    prefix: '/api/schema'
});

/**
 * @swagger
 * /api/schema/models:
 *   get:
 *     summary: 获取所有数据模型列表
 *     tags: [Schema]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 10
 *         description: 每页显示数量
 *       - in: query
 *         name: name
 *         schema:
 *           type: string
 *         description: 模型名称搜索关键词
 *     responses:
 *       200:
 *         description: 成功获取模型列表
 */
router.get('/models', authenticate, schemaController.getModels);

/**
 * @swagger
 * /api/schema/models/{model}:
 *   get:
 *     summary: 获取指定模型的结构信息
 *     tags: [Schema]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: model
 *         required: true
 *         schema:
 *           type: string
 *         description: 模型名称
 *     responses:
 *       200:
 *         description: 成功获取模型结构
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 操作成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     modelName:
 *                       type: string
 *                       description: 模型名称
 *                     fields:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           field:
 *                             type: string
 *                             description: 字段名
 *                           type:
 *                             type: string
 *                             description: 字段类型
 *                           required:
 *                             type: boolean
 *                             description: 是否必填
 *                           default:
 *                             type: string
 *                             description: 默认值
 *                           unique:
 *                             type: boolean
 *                             description: 是否唯一
 *                           ref:
 *                             type: string
 *                             description: 引用的模型
 *                           enum:
 *                             type: array
 *                             description: 枚举值列表
 *                     indexes:
 *                       type: array
 *                       description: 索引信息
 *                     timestamps:
 *                       type: boolean
 *                       description: 是否启用时间戳
 *       404:
 *         description: 模型不存在
 */
router.get('/models/:model', authenticate, schemaController.getModelSchema);

/**
 * @swagger
 * /api/schema/models/{model}/data:
 *   get:
 *     summary: 获取指定模型的数据列表
 *     tags: [Schema]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: model
 *         required: true
 *         schema:
 *           type: string
 *         description: 模型名称
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 10
 *         description: 每页显示数量
 *       - in: query
 *         name: name
 *         schema:
 *           type: string
 *         description: 名称搜索关键词
 *     responses:
 *       200:
 *         description: 成功获取数据列表
 */
router.get('/models/:model/data', authenticate, schemaController.getModelData);

module.exports = router; 